
*=============================================================================

*** Setup

version 15
capture log close
set more off
clear all

* Load data
use "$data/01 Raw Data/03 Germany/STAN0125_DE_output.dta" 

*=============================================================================

*** Time Path Question

* Cost treatment indicator

gen coststreaty=CCD_treatment
label define costs 1 "€39" 3 "€154"
lab values coststreaty costs
gen D_coststreaty=.
replace D_coststreaty=0 if coststreaty==1
replace D_coststreaty=1 if coststreaty==3
label var D_coststreaty "Costs High (€154)"

* Outcome

/* 
1 Costs remain the same over the entire period
2 Costs are lower initially and higher later
3 Costs are higher initially and lower later
4 Costs are lower initially, higher in the middle, and lower later
*/

gen cpath=.
replace cpath=1 if Q4_4==1
replace cpath=2 if Q4_4==2
replace cpath=3 if Q4_4==3
replace cpath=4 if Q4_4==4
lab var cpath "Dynamic Climate Cost Preferences"
lab define cpath_lab 1 "Constant" 2 "Increasing" 3 "Decreasing" 4 "Inverse U"
lab values cpath cpath_lab
tab cpath

* Recode so that increasing is the baseline
recode cpath (2=1) (1=2) (3=3) (4=4), gen(cpath_inc)
tab cpath_inc
label define cpath_inc_lab 1 "Increasing" 2 "Constant" 3 "Decreasing" 4 "Inverse U" 
label values cpath_inc cpath_inc_lab

* Generate indicators
tab cpath_inc, gen(pref_)
rename pref_1 pref_inc
rename pref_2 pref_const
rename pref_3 pref_dec
rename pref_4 pref_invu

*=============================================================================

*** Ideology (3 groups)

gen lrideo=LRSP_11
lab var lrideo "Left (1)-Right (10) Ideology"

gen ideo_left=.
replace ideo_left=1 if lrideo<6
replace ideo_left=0 if lrideo>=6 & lrideo!=.

gen ideo_middle=.
replace ideo_middle=1 if lrideo==6
replace ideo_middle=0 if lrideo!=6 & lrideo!=.

gen ideo_right=.
replace ideo_right=1 if lrideo>6 
replace ideo_right=0 if lrideo<=6 & lrideo!=.

*=============================================================================

*** Gender

gen female=.
replace female=0 if DEMO_gender==1
replace female=1 if DEMO_gender==2
lab var female "Female"

*=============================================================================

*** Age

gen age=2018-DEMO_AGE
lab var age "Age"

* Drop if age<18
drop if age<18

* Dummies
gen age1834=(age>=18 & age<=34)
gen age3549=(age>=35 & age<=49)
gen age5064=(age>=50 & age<=64)
gen age65above=(age>=65 & age!=.)

* Categories
gen agegroups=.
lab var agegroups "Age Groups"
replace agegroups=1 if age1834==1
replace agegroups=2 if age3549==1
replace agegroups=3 if age5064==1
replace agegroups=4 if age65above==1

lab define agegroups 1 "18-34" 2 "35-49" 3 "50-64" 4 "65+"
lab values agegroups agegroups

*=============================================================================

*** Income

* Quantile groups
recode DEMO_faminc (1/3=1) (4/5=2) (6/9=3) (10/15=4) (else=.), gen(inc_group)
lab define inc_group_lab 1 "Income: Low" 2 "Income: Lower Middle" 3 "Income: Upper Middle" 4 "Income: High"
label values inc_group inc_group_lab
label var inc_group "Income Groups"
tab inc_group

* Dummies
gen income=DEMO_faminc
replace income=. if DEMO_faminc>13
su income, det

gen inc_bin_high=.
replace inc_bin_high=0 if income<=`r(p50)'
replace inc_bin_high=1 if income>`r(p50)' & income!=.
label var inc_bin_high "Income: Above Median"

gen inc_low=0 if income!=.
replace inc_low=1 if income>1 & income<=4 & income!=.

gen inc_med=0 if income!=.
replace inc_med=1 if income>4 & income<=7  & income!=.

gen inc_high=0 if income!=.
replace inc_high=1 if income>7 & income!=.

*=============================================================================

*** Employment

gen unempl=0
replace unempl=1 if DEMO_employ==3 | DEMO_employ==5

*=============================================================================

*** Education

/*
Years / Code / Label
16 and less	<1> ohne Haupt-/Volksschulabschluss
16 and less	<2> Haupt-/Volksschulabschluss
16 and less	<3> Mittlere Reife, Realschulabschluss, Fachschulreife
17-18	<4> Abschluss der Polytechnischen Oberschule (8./10.Klasse)
17-18	<5> Fachhochschulreife, Abschluss einer Fachoberschule
17-18	<6> Abitur, allgemeine oder fachgebundene Hochschulreife
19+	<7> Fach-/ Hochschulstudium
*/

* Dummies

g less_than_hs=0
replace less_than_hs=1 if (DEMO_educ==1 | DEMO_educ == 2) & DEMO_educ!=.
lab var less_than_hs "Less than HS"

g hs=0
replace hs=1 if (DEMO_educ >=3 & DEMO_educ <=6) & DEMO_educ!=.
lab var hs "HS graduate"

g ba=0
replace ba=1 if DEMO_educ== 7 & DEMO_educ!=.
lab var ba "BA or higher"

* Categories
gen school_lowtier=0 if DEMO_educ!=.
replace school_lowtier=1 if less_than_hs == 1

gen school_medtier=0 if DEMO_educ!=.
replace school_medtier=1 if hs == 1

gen school_hightier=0 if DEMO_educ!=.
replace school_hightier=1 if ba == 1

* Years of schooling
gen educ_yrs=.
label var educ_yrs "Education Years: 1=16 or less, 2=17-18, 3=19+"
label define educ_yrs_lab 1 "16 or less" 2 "17-18" 3 "19+"
label values educ_yrs educ_yrs_lab

replace educ_yrs=1 if DEMO_educ>=1 & DEMO_educ<=3
replace educ_yrs=2 if DEMO_educ>=4 & DEMO_educ<=6
replace educ_yrs=3 if DEMO_educ==7

*=============================================================================

*** Children

gen children=0
replace children=1 if DEMO_children>0

*=============================================================================

*** Saving

compress
save "$data/de_prep_import.dta", replace
